package com.desay.pangoo.itmt.repository;

import java.util.List;
import java.util.Set;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import com.desay.pangoo.itmt.entity.OrgChartEntity;
import com.desay.pangoo.itmt.entity.WorkGroupEntity;

/**
 * @author uidq1163
 */
@Repository
public interface OrgChartRepository
		extends JpaSpecificationExecutor<OrgChartEntity>, PagingAndSortingRepository<OrgChartEntity, Long> {

	/**
	 * 根据用户组查询用户
	 * 
	 * @param workGroup
	 * @return
	 */
	Set<OrgChartEntity> findByWorkGroup(WorkGroupEntity workGroup);

	/**
	 * 根据用户组和角色查询用户
	 * 
	 * @param workGroup
	 * @param orgRole
	 *            组织角色:ITMT ChairMan:1，ITMT Leader:2，ITMT
	 *            SubLeader:3，ITMT成员:4，TSP:5
	 * @return
	 */
	OrgChartEntity findByWorkGroupAndOrgRole(WorkGroupEntity workGroup, Integer orgRole);

	/**
	 * 根据用户组和角色查询用户
	 * 
	 * @param workGroup
	 * @param orgRoles
	 *            组织角色:ITMT ChairMan:1，ITMT Leader:2，ITMT
	 *            SubLeader:3，ITMT成员:4，TSP:5
	 * @return
	 */
	Set<OrgChartEntity> findByWorkGroupAndOrgRoleIn(WorkGroupEntity workGroup, List<Integer> orgRoles);

	/**
	 * 根据角色获取用户信息
	 * 
	 * @param orgRole
	 * @return
	 */
	List<OrgChartEntity> findByOrgRole(Integer orgRole);

	/**
	 * 根据登录名和角色获取用户信息
	 * 
	 * @param login
	 * @param orgRole
	 * @return
	 */
	List<OrgChartEntity> findByLoginInAndOrgRole(Set<String> login, Integer orgRole);

	/**
	 * 根据角色获取用户信息
	 * 
	 * @param orgRoles
	 * @return
	 */
	Set<OrgChartEntity> findByOrgRoleIn(List<Integer> orgRoles);

	/**
	 * 根据NickName统计全体成员人数
	 * 
	 * @return
	 */
	@Query("SELECT COUNT(DISTINCT org.nickName) FROM OrgChartEntity org")
	long countDistinctByNickName();
}